home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / dlx70bbs.zip / DLX70SRC.ZIP / COM_PAX2.ASM < prev    next >
Assembly Source File  |  1994-01-19  |  41KB  |  1,451 lines

  1. ; COM_PAX2.ASM
  2. ; Communications Package for the IBM PC, XT, AT, Clones
  3. ; Extensively modified for DLX -- not for general use
  4. ; 32 line version -- both com/8 and mc/8
  5.  
  6. ; port1    port2
  7. ; 3f8    2f8    com1=line1  /  com2=line2
  8. ; 3f8    other    com1=line1  /  com2 com/x lines 2-9
  9. ; other    2f8    com1 com/x lines 1-8  /  com2=line9
  10. ; other    other    com1 com/x lines 1-8,17-24  /  com2 com/x lines 9-16,25-32
  11.  
  12. ; DLX Bulletin Board System V7.0
  13.  
  14. ; FREEWARE NOTICE
  15.  
  16. ; DLX V7.0 is placed in the public domain by its author, Richard Gillmann.
  17. ; Anyone who wishes to may run the program, copy it, or modify it for
  18. ; any purpose, including commercial gain.
  19.  
  20. ; o Special features for BBSes
  21. ; o Uses MS Pascal calling conventions
  22. ; o Supports all serial ports simultaneously
  23. ; o All speeds to 19200 baud
  24. ; o Compatible with PC, XT, AT (not PCjr or PS/2 alas)
  25. ; o Built in XON/XOFF flow control
  26. ; o I/O buffers not in DGROUP
  27.  
  28. ; boolean constants
  29. true        equ    1        ; what MS Pascal
  30. false        equ    0        ; believes
  31. ; params
  32. wrapcol        equ    74        ; hard wrap at this column
  33. nlines        equ    32        ; number of lines
  34. ; maximum buffer sizes
  35. r_size        equ     360        ; size of receive buffers
  36. s_size        equ     180        ; size of transmit buffers
  37. ; ascii
  38. bs        equ    8        ; backspace
  39. tab        equ    9        ; tab
  40. lf        equ    10        ; linefeed
  41. cr        equ    13        ; carriage return
  42. del        equ    127        ; del
  43. ; interrupt numbers
  44. int_com1     equ    0ch        ; com1: from 8259
  45. int_com2     equ    0bh        ; com2: from 8259
  46. ; 8259 ports
  47. inta00      equ     20h        ; 8259a port, a0 = 0
  48. inta01      equ     21h        ; 8259a port, a0 = 1
  49. ; com1: level 4
  50. irq4        equ    2*2*2*2        ; 8259a ocw1 mask, m4=1, a0=0
  51. nirq4        equ    not irq4 and 0ffh ; complement of above
  52. eoi4        equ    4 or 01100000b    ; 8259a ocw2 specific irq4 eoi, a0=0
  53. ; com2: level 3
  54. irq3        equ    2*2*2        ; 8259a ocw1 mask, m3=1, a0=0
  55. nirq3        equ    not irq3 and 0ffh ; complement of above
  56. eoi3        equ    3 or 01100000b    ; 8259a ocw2 specific irq3 eoi, a0=0
  57. ; flow control characters
  58. control_q     equ    11h        ; xon
  59. control_s     equ    13h        ; xoff
  60. ; misc.
  61. control_c     equ    3h        ; control c
  62. control_o     equ    0fh        ; control o
  63. dos        equ    21h        ; dos function calls
  64.  
  65. pushem        macro
  66.         push    bp
  67.         mov    bp,sp
  68.         push    ds
  69.         mov    ax,data2
  70.         mov    es,ax
  71.         endm
  72.  
  73. popem        macro
  74.         pop    ds
  75.         pop    bp
  76.         endm
  77.  
  78. ;
  79. ; rom bios data area
  80. ;
  81. rbda        segment    at 40h
  82.         org    6ch
  83. timer_low    dw    ?        ; low word of bios timer count
  84. rbda        ends
  85.  
  86. ;
  87. ; table for each serial port
  88. ;
  89. sp_tab        struc
  90. port        db    ?        ; 1..nlines
  91. ; buffer displacements
  92. di_tdata    dw    ?        ; offset to our part of tdata
  93. di_rdata    dw    ?        ; offset to our part of rdata
  94. ; attributes
  95. baud_rate    dw    ?        ; 300 to 9600 baud ok
  96. parity        db    ?        ; n(one) o(dd) e(ven) s(pace) m(ark)
  97. stop_bits    db    ?        ; 1, 2
  98. echo_state    db    ?        ; 1=echo 0=no echo
  99. chars_this_line    db    ?        ; chars on this line so far
  100. woscol        db    ?        ; wrap on space column
  101. ; flow control state
  102. host_off    db    ?        ; host xoffed (1=yes,0=no)
  103. pc_off        db    ?        ; pc xoffed (1=yes,0=no)
  104. cancelled    db    ?        ; flag if control c seen
  105. skipped        db    ?        ; flag if control o seen
  106. timeout        dw    ?        ; timeout clock
  107. warnout        db    ?        ; warning flag
  108. binary        db    ?        ; xmodem flag
  109. soft_cr        db    ?        ; soft carriage return (1=yes,0=no)
  110. ; 8250 ports
  111. datreg        dw    ?        ; data register
  112. ier        dw    ?        ; interrupt enable register
  113. iir        dw      ?        ; interrupt identification register
  114. lcr        dw      ?        ; line control register
  115. mcr        dw      ?        ; modem control register
  116. lsr        dw      ?        ; line status register
  117. msr        dw      ?        ; modem status register
  118. ; buffer pointers
  119. start_tdata     dw      ?           ; index to 1st character in xmit buf
  120. end_tdata       dw      ?           ; index to 1st free space in xmit buf
  121. start_rdata     dw      ?           ; index to 1st character in rec buf
  122. end_rdata       dw      ?        ; index to 1st free space in rec buf
  123. ; buffer counts
  124. size_tdata      dw      ?        ; number of characters in x-mit buffer
  125. size_rdata      dw      ?           ; number of characters in rec. buffer
  126. sp_tab        ends
  127. ; sp_tab equates
  128. ; we have to use these because of problems with struc
  129. dll        equ    datreg        ; low divisor latch
  130. dlh        equ    ier        ; high divisor latch
  131.  
  132. data2    segment    public 'DATA'
  133. ; i/o buffers (not in DGROUP)
  134. tdata        db      nlines*s_size dup(?) ; send buffers
  135. rdata        db    nlines*r_size dup(?) ; receive buffers
  136. data2    ends
  137.  
  138.     extrn    to_warn:word,to_kill:word,hostecho:byte,dcd_ok:byte
  139.     extrn    ps2mc8:byte
  140.     public    com1_port,com2_port,status_port1,status_port2,bits8,eskape
  141. data    segment public 'DATA'
  142. com1_port    dw    3f8h        ; port address / int4
  143. com2_port    dw    2f8h        ; port address / int3
  144. status_port1    dw    140h        ; digiboard status / int4
  145. status_port2    dw    140h        ; digiboard status / int3
  146. old_com_off1    dw    ?        ; old handler's offset level 4
  147. old_com_seg1    dw    ?        ; old handler's segment level 4
  148. old_com_off2    dw    ?        ; old handler's offset level 3
  149. old_com_seg2    dw    ?        ; old handler's segment level 3
  150. temp        dw    0        ; temp used by echo_com
  151. bpp        db    8        ; bytes per port in i/o address space
  152. bits8        db    7fh        ; mask applied to incoming characters
  153. div50        dw    2304        ; pc/xt/at divisor for 50 baud
  154. area_length    dw    type sp_tab    ; length of param block
  155. current_area    dw    area1        ; currently selected area
  156. channel        db    0        ; current mc/8 channel
  157.  
  158. ; data areas for each port
  159. atabl    macro    x
  160. area&x    sp_tab    <x,(x-1)*s_size,(x-1)*r_size>
  161.     endm
  162.  
  163. y    =    0
  164.     rept    nlines
  165. y    =    y + 1
  166.     atabl    %y
  167.     endm
  168.  
  169. ; filter for incoming characters (0 means ignore them)
  170. ; disallows certain characters, also strips parity
  171. filter    db    3 dup(0)
  172.     db    7fh        ; control-c
  173.     db    4 dup(0)
  174.     db    7fh        ; bs
  175.     db    7fh        ; tab
  176.     db    7fh        ; lf
  177.     db    2 dup(0)
  178.     db    7fh        ; cr
  179.     db    7fh        ; double note for music
  180.     db    7fh        ; control-o
  181.     db    0
  182.     db    7fh        ; control-q
  183.     db    0
  184.     db    7fh        ; control-s
  185.     db    7 dup(0)
  186. eskape    db    0        ; escape
  187.     db    4 dup(0)
  188.     db    95 dup(7fh)    ; printable ascii
  189.     db    7fh        ; del
  190.     db    128 dup(0ffh)    ; upper chars for europe
  191. tabsiz    db    8        ; tab spacing
  192. data    ends
  193. dgroup    group    data
  194.  
  195. auxhndlr segment 'CODE'
  196.     assume  cs:auxhndlr,ds:dgroup,ss:dgroup,es:data2
  197. ; 8259
  198.     public    save_com    ; save old interrupt vector
  199.     public  installc    ; install our interrupt vector
  200.     public  restorec    ; restore old interrupt vector
  201. ; 8250
  202.     public    select_port    ; select communications port
  203.     public  open_com    ; initialize port
  204.     public  close_com       ; turn off interrupts from com port
  205.     public  dtr_off        ; turn off dtr
  206.     public  dtr_on        ; turn on dtr
  207.     public    rlsd        ; return rlsd (still on-line if true)
  208.     public    warning        ; return true if time to warn of timeout
  209.     public    unwarn        ; cancel timeout warning
  210.     public  r_count        ; return number of characters in input buffer
  211.     public  receive        ; read next character in input buffer
  212.     public  s_free        ; return no. of free bytes in output buffer
  213.     public  s_working    ; return no. of chars waiting in output buffer
  214.     public  send        ; write a character to output buffer
  215.     public    echo_com    ; echo to sender again
  216.     public    purge_com    ; empty buffers
  217.     public    unskip_com    ; stop skipping
  218.     public    cancelled_com    ; have we been control c-ed?
  219.     public    force_cancel    ; simulate control-C
  220.     public    skipped_com    ; have we been control o-ed?
  221.     public    wrap        ; set wrap column
  222.     public    binary_mode    ; toggle binary mode
  223.     public    was_soft    ; was that a soft carriage return?
  224.     page
  225. ;
  226. ; internal buffer routines
  227. ; at this point, si is already set up
  228. ;   gst = get from start of tdata (to al)
  229. ;   gsr = get from start of rdata (to al)
  230. ;   pet = put (from al) to end of tdata (preserves al)
  231. ;   per = put (from al) to end of rdata (preserves al)
  232. ;   pst = put (from al) to start of tdata (preserves al)
  233. ; to be safe, call these with interrupts off
  234. ;
  235. gst    proc    near            ; *call with interrupts off*
  236.     mov    al,0            ; in case of underflow
  237.     cmp    size_tdata[si],0    ; any characters?
  238.     je    gst_x            ; jump if not
  239.     mov     bx,start_tdata[si]    ; bx points to next char. to be sent
  240.     mov    di,di_tdata[si]
  241.     mov     al,tdata[di][bx]    ; get data from buffer
  242.     inc     bx            ; increment start_tdata
  243.     cmp     bx,s_size        ; see if gone past end
  244.     jb      gst_1            ; if not then skip
  245.     mov    bx,0            ; reset to beginning
  246. gst_1:    mov     start_tdata[si],bx    ; save start_tdata
  247.     dec     size_tdata[si]        ; one less character in x-mit buffer
  248. gst_x:    ret                ; done
  249. gst    endp
  250. ;
  251. gsr    proc    near
  252.     mov    ax,0            ; in case of underflow
  253.     cmp    size_rdata[si],0    ; any character